package com.ganmiao.utils;

import lombok.extern.slf4j.Slf4j;

import java.util.Random;

@Slf4j
public class StringCodeUtil {

    private static final String UPPER_CHARACTER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private static final String LOWER_CHARACTER = "abcdefghijklmnopqrstuvwxyz";
    private static final String NUMBER = "0123456789";

    private static final String RAN_CHARACTER = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

    public static String generateUpperCharacter(int length) {
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(UPPER_CHARACTER.length());
            sb.append(UPPER_CHARACTER.charAt(index));
        }

        return sb.toString();
    }

    public static String generateLowerCharacter(int length) {
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(LOWER_CHARACTER.length());
            sb.append(LOWER_CHARACTER.charAt(index));
        }

        return sb.toString();
    }

    public static String generateNumber(int length) {
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(NUMBER.length());
            sb.append(NUMBER.charAt(index));
        }

        return sb.toString();
    }

    public static String generateRandomStr(int length) {
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(RAN_CHARACTER.length());
            sb.append(RAN_CHARACTER.charAt(index));
        }

        return sb.toString();
    }

}
